package com.sinosoft.dsp.platform.components.portal.input;

import com.sinosoft.dsp.system.utils.Const;
import com.sinosoft.dsp.system.utils.StringUtil;

public enum SinoSearchFormConditionType {
	// 单列
	SINGLE,

	// 单列-所有列
	SINGLE_ALL,

	// 单列-自然
	SINGLE_NORMAL,

	// 强制换行
	BREAK,

	// 正常
	NORMAL,

	// 数字
	NUMBER;

	public static SinoSearchFormConditionType getType(String condition) {
		if (!Const.isEmpty(condition)) {
			String c = condition.toUpperCase().replaceAll(" ", "");
			for (SinoSearchFormConditionType type : SinoSearchFormConditionType
					.values()) {
				if (c.indexOf("(" + type.name() + ")") != -1) {
					return type;
				}
			}

			String[] strs = c.split("\\(");
			if (strs.length == 2) {
				String num = strs[1].substring(0, strs[1].length() - 1);
				if (StringUtil.isInteger(num)) {
					return NUMBER;
				}
			}
		}

		return NORMAL;
	}

	public static int getNumber(String condition) {
		String[] strs = condition.split("\\(");
		if (strs.length == 2) {
			String num = strs[1].substring(0, strs[1].length() - 1);
			if (StringUtil.isInteger(num)) {
				return Integer.valueOf(num);
			}
		}
		return 1;
	}

	public static String getId(String condition) {
		if (!Const.isEmpty(condition)) {
			return condition.split("\\(")[0];
		}
		return null;
	}
}
